<template>
    <div>
        <!--面包屑导航区域-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home_com' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>岗位信息</el-breadcrumb-item>
        </el-breadcrumb>
        <!--卡片视图区域-->
        <el-card>
            <!--搜索区域-->
            <el-row>
                <el-col :span="9">
                    <el-input placeholder="Please input" v-model="queryInfo.query" clearable @clear="getpos_comList">
                        <template #append>
                            <el-button type="primary" @click="getpos_comList">
                                <el-icon style="vertical-align: middle;">
                                    <search />
                                </el-icon>
                                <span style="vertical-align: middle;"> Search </span>
                            </el-button>
                        </template>
                    </el-input>
                </el-col>
                <el-col :span="4"></el-col>
            </el-row>
            <!--岗位列表区域-->
            <el-table :data="poslist" :border="true" :stripe="true">
                <el-table-column prop="posID" label="编号"></el-table-column>
                <el-table-column prop="name" label="岗位名称"></el-table-column>
                <el-table-column prop="type" label="岗位类别"></el-table-column>
                <el-table-column prop="company" label="所属公司"></el-table-column>
                <el-table-column prop="salary" label="最低薪资"></el-table-column>
                <el-table-column label="详情">
                    <template v-slot="scope">
                        <el-button type="success" @click="showDialog(scope.row.posID)">查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页区域-->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
        <!--查看详情对话框-->
        <el-dialog title="岗位详情" v-model="Visible" width="50%" @close="DialogClosed">
            <!--内容主体区域-->
            <el-descriptions class="margin-top" title="详情信息" :column="3" :size="size" border>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位编号
                        </div>
                    </template>
                    {{this.detail.posID}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位名称
                        </div>
                    </template>
                    {{this.detail.posName}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位大类
                        </div>
                    </template>
                    {{this.detail.bigType}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位小类
                        </div>
                    </template>
                    {{this.detail.smallType}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            最低薪资
                        </div>
                    </template>
                    {{this.detail.salary}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            实习期
                        </div>
                    </template>
                    {{this.detail.intern}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            工作地点
                        </div>
                    </template>
                    {{this.detail.site}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            所属公司
                        </div>
                    </template>
                    {{this.detail.comp}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            负责HR
                        </div>
                    </template>
                    {{this.detail.posHR}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位要求
                        </div>
                    </template>
                    {{this.detail.request}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            岗位职责
                        </div>
                    </template>
                    {{this.detail.response}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            审核状态
                        </div>
                    </template>
                    {{this.detail.flag}}
                </el-descriptions-item>
            </el-descriptions>
            <!--底部区域-->
            <span slot="footer" class="dialog-footer">
                <el-button @click="Visible = false" class="btns">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>

export default {
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            poslist: [

            ],
            //查看岗位详情
            detail: {
                posID: 0,
                posName: '',
                bigType: '',
                smallType: '',
                salary: 0,
                intern: 0,
                site: '',
                comp: '',
                posHR: '',
                request: '',
                response: '',
                flag: 0
            },
            total: 0,
            //控制查看详情对话框的显示与隐藏
            Visible: false
        }
    },
    created() {
        this.getpos_comList();
    },
    methods: {
        async getpos_comList() {
            const { data: res } = await this.$http.post('getPositionList', this.queryInfo)
            if (res.error_code !== 0) {
                return this.$message.error('获取岗位信息失败！')
            }
            this.poslist = []
            this.total = this.total = res.pageTotal;
            for(var i = 0; i < this.total; i++) {
                if(res.data.PositionList[i].flag === 0) {
                    continue;
                }
                this.poslist.push({
                    posID: res.data.PositionList[i].posID,
                    name: res.data.PositionList[i].posName,
                    type: res.data.PositionList[i].smallType,
                    company: res.data.PositionList[i].comp,
                    salary: res.data.PositionList[i].salary
                });
            }
        },
        //监听pagesize 改变的事件
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getpos_comList();
        },
        //监听页码值改变的事件
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getpos_comList();
        },
        //监听查看详情对话框的关闭事件
        DialogClosed() {
            this.Visible = false
        },
        //展示查看详情对话框
        async showDialog(id) {
            const json = {
                posID: id
            };
            console.log(json);
            const { data: res } = await this.$http.post('getPositionByID' , json)
            if(res.error_code !== 0){
                return this.$message.error('查看详情失败！')
            }
            this.detail = res.data
            this.detail.flag = res.data.flag === 0 ? '未审核':'通过';
            this.detail.intern = res.data.intern === 0 ? '否':'是';
            this.Visible = true
        }
    }
}
</script>

<style lang="less" scoped>
.btns {
    margin-top: 15px;
}
</style>